﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Process.Infastructure.Migrations
{
    /// <inheritdoc />
    public partial class db : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "bomTables",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    BOMCode = table.Column<string>(type: "nvarchar(450)", nullable: false),
                    BOMTitle = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ProductGoodsId = table.Column<int>(type: "int", nullable: true),
                    ProductsCode = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ProductsName = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ProductsModel = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ProductsUnit = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Brand = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Status = table.Column<bool>(type: "bit", nullable: false),
                    Version = table.Column<string>(type: "nvarchar(450)", nullable: false),
                    Output = table.Column<int>(type: "int", nullable: false),
                    Desc = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Creater = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Updater = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    IsDelete = table.Column<bool>(type: "bit", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_bomTables", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "goodsinfo",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    GoodsCode = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    GoodsName = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    GoodsModel = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Unit = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    GoodsType = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    MinStock = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
                    MaxStock = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
                    Stock = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
                    Price = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
                    Status = table.Column<bool>(type: "bit", nullable: false),
                    Remark = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Creater = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Updater = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    IsDelete = table.Column<bool>(type: "bit", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_goodsinfo", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "bomGoodsRelations",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    BomTableId = table.Column<int>(type: "int", nullable: false),
                    GoodsinfoId = table.Column<int>(type: "int", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Creater = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Updater = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    IsDelete = table.Column<bool>(type: "bit", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_bomGoodsRelations", x => x.Id);
                    table.ForeignKey(
                        name: "FK_bomGoodsRelations_bomTables_BomTableId",
                        column: x => x.BomTableId,
                        principalTable: "bomTables",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_bomGoodsRelations_goodsinfo_GoodsinfoId",
                        column: x => x.GoodsinfoId,
                        principalTable: "goodsinfo",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "bomFlowRelations",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    BomTableId = table.Column<int>(type: "int", nullable: false),
                    ProcessFlowId = table.Column<int>(type: "int", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Creater = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Updater = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    IsDelete = table.Column<bool>(type: "bit", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_bomFlowRelations", x => x.Id);
                    table.ForeignKey(
                        name: "FK_bomFlowRelations_bomTables_BomTableId",
                        column: x => x.BomTableId,
                        principalTable: "bomTables",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_bomFlowRelations_processFlows_ProcessFlowId",
                        column: x => x.ProcessFlowId,
                        principalTable: "processFlows",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateIndex(
                name: "IX_bomGoodsRelations_BomTableId",
                table: "bomGoodsRelations",
                column: "BomTableId");

            migrationBuilder.CreateIndex(
                name: "IX_bomGoodsRelations_GoodsinfoId",
                table: "bomGoodsRelations",
                column: "GoodsinfoId");

            migrationBuilder.CreateIndex(
                name: "IX_bomFlowRelations_BomTableId",
                table: "bomFlowRelations",
                column: "BomTableId");

            migrationBuilder.CreateIndex(
                name: "IX_bomFlowRelations_ProcessFlowId",
                table: "bomFlowRelations",
                column: "ProcessFlowId");

            migrationBuilder.CreateIndex(
                name: "IX_bomTables_BOMCode_Version",
                table: "bomTables",
                columns: new[] { "BOMCode", "Version" },
                unique: true);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "bomFlowRelations");

            migrationBuilder.DropTable(
                name: "bomGoodsRelations");

            migrationBuilder.DropTable(
                name: "bomTables");

            migrationBuilder.DropTable(
                name: "goodsinfo");
        }
    }
}
